package toDoList.Controllers;

import toDoList.Manager.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.Spinner;
import android.widget.TimePicker;

public class DatePickerController extends Activity implements ControllerInterface {
	
	/** Called when the activity first starts */
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.datepicker);
    }
	
	/**
	 * createListener() Ties all of the controllers together
	 */
	public void createListener()
	{
		
	}
	
	
	/**
	 * okPressed(View view) Runs when the ok button is pressed. Passes back the date and time chosen by the user.
	 * @param view The current view on the screen
	 */
	public void okPressed(View v)
	{
		Intent data = new Intent();
		
		//Add the date and time as data
		int month = ((DatePicker)findViewById(R.id.datePicker)).getMonth() + 1;
		int day = ((DatePicker)findViewById(R.id.datePicker)).getDayOfMonth();
		int year = ((DatePicker)findViewById(R.id.datePicker)).getYear();
		int hour = ((TimePicker)findViewById(R.id.timePicker)).getCurrentHour();
		int min = ((TimePicker)findViewById(R.id.timePicker)).getCurrentMinute();
		
		data.putExtra("month", String.valueOf(month));
		data.putExtra("day", String.valueOf(day));
		data.putExtra("year", String.valueOf(year));
		data.putExtra("hour", String.valueOf(hour));
		data.putExtra("min", String.valueOf(min));
		
		setResult(Activity.RESULT_OK, data);
		finish();
	}
	
	/**
	 * cancelPressed(View view) Cancels this view. Reverts back to the previous view on the stack.
	 * @param view The current view on the screen
	 */
	public void cancelPressed(View v)
	{
		Intent data = new Intent();
		setResult(Activity.RESULT_CANCELED, data);
		finish();
	}
}
